//
// Created by YxMin on 2024/7/4.
//

#ifndef GAME_ELEMENT_H
#define GAME_ELEMENT_H
#include <easyx.h>
class Element {
protected:
    RECT area{};
    int uid;
    int radius;
    int(*callback)(void*) = nullptr;
    int(*DoubleClickCallback)(void*) = nullptr;
public:
    virtual void draw() = 0; //即画出此元素
    void erase() const {
        if(radius > 0) {
            clearroundrect(area.left,area.top,area.right,area.bottom,radius,radius);
        } else {
            clearrectangle(area.left,area.top,area.right,area.bottom);
        }
    }
    Element() = default;
    Element(int uid,int x1,int y1,int x2,int y2,int radius = 0,int(*callback)(void*) = nullptr);
    virtual ~Element() = default;
    bool isInteractive() {
        return callback != nullptr;
    }
    bool canDoubleClick() {
        return DoubleClickCallback != nullptr;
    }
    int getUI() {
        return uid;
    }
    int (*getCallback())(void*) {
        return callback;
    }
    void setDoubleClickCallback(int(*call)(void*));
    int (*getDoubleClickCallback())(void*) {
        return DoubleClickCallback;
    }
    RECT getArea() {
        return area;
    }
    void showText(LPCTSTR text) {
        drawtext(text,&area,DT_CENTER|DT_VCENTER|DT_SINGLELINE);
    }
    bool contains(int x,int y) {
        return area.left <= x && area.top <= y && x <= area.right && y <= area.bottom;
    }
};
#endif //GAME_ELEMENT_H
